//查询
systemConfigurationList()
function systemConfigurationList() {
    $.ajax({
        url:root.serviceProviderManagement.select,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            "pageNumber": 1,
            "pageSize": 20
        }),
        success: function (data) {
            systemConfigurationtable(data.result, 0);
            $('.M-box3').pagination({
                pageCount: data.totalPage,
                jump: true,
                coping: true,
                prevContent: '上页',
                nextContent: '下页',
                callback: function (api) {
                    $.ajax({
                        url: root.serviceProviderManagement.select,
                        cache: false,  //禁用缓存
                        type: "POST",
                        dataType:'json',
                        contentType: "application/json",
                        data: JSON.stringify({
                            "pageNumber":api.getCurrent(),
                            "pageSize":20,
                        }),
                        success: function (result) {
                            systemConfigurationtable(result.result);
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(XMLHttpRequest);
                        }
                    });
                }
            });

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
var dataSource = new Array();
var table;   //table对象
dataSource = [];
function systemConfigurationtable(data, index){
    sessionStorage.setItem("authorizedUsers", JSON.stringify(data));
    dataSource.splice(0,dataSource.length);//清空数组
    if(data !=null && data != ''){
        $.each(data, function (i, field) {
            var rowData = new Array();
            rowData.push(field.channelId);
            rowData.push(field.channelName);
            rowData.push(field.autoSplitStatus);
            rowData.push(field.manualAssignStatus);
            rowData.push(field.createdAt);
            rowData.push(field.updateUserName);
            rowData.push(field.id);
            dataSource.push(rowData);

        });

    }
    initDataTable(dataSource);
    function initDataTable(dataSource) {

        var dttable = $('#systemConfigurationtable').dataTable(); // 初始化dataTable，清空上一个值
        dttable.fnClearTable(); //清空一下table
        dttable.fnDestroy(); //还原初始化了的datatable
        $("#systemConfigurationtable").DataTable({
            // "order": false,
            "autoWidth": false,
            "ordering": false,
            "searching": false,
            "paging": false,
            "retrieve": true,
            "destroy": true,
            "bAutoWidth": true,
            "bLengthChange": true,
            "aLengthMenu": false,
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                },
                "sZeroRecords": "没有检索到数据",
            },
            data: dataSource,
            columnDefs: [
                {
                    "visible": true,
                    "targets": 0
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[0]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 0
                },

                {
                    "render": function (data, type, row, meta) {
                        var val = row[1]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 1
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[2]
                        if (val == 10) {
                            val = '开启'
                        }else if (val == 20) {
                            val = '关闭'
                        }
                        return val;
                    },
                    "targets":2
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[3]
                        if (val == 10) {
                            val = '开启'
                        }else if (val == 20) {
                            val = '关闭'
                        }
                        return val;
                    },
                    "targets":3
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[4]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 4
                },
                {
                    "render": function (data, type, row, meta) {
                        var val = row[5]
                        if (val == undefined) {
                            val = ''
                        }
                        return val;
                    },
                    "targets": 5
                },
                {
                    "render": function (data, type, row, meta) {
                        var val='<span class="ml-10"><a onclick="jumpData(\'修改\',\'orderSetting.html?configId='+row[6]+'\')">修改</a></span>'
                        return val;
                    },
                    "targets": 6
                }


            ]
        });
        //权限控制函数
        power()
    };
}

//跳转
function jumpData(title,url,) {
    var index = layer.open({
        type: 2,
        title: title,
        content: url
    });
    layer.full(index);
}
